﻿using System.Linq;

using Microsoft.WowAddonStudio.Lua.AST;
using Microsoft.WowAddonStudio.Lua.Model;
using Microsoft.WowAddonStudio.Lua.Support;

using Function = Microsoft.WowAddonStudio.Lua.AST.Function;

namespace Microsoft.WowAddonStudio.Lua.Adapters
{
    /// <summary>
    /// Adds documentation for the <see cref="FunctionDeclaration"/> nodes in the AST.
    /// </summary>
    public class FunctionDocumentationAdapter : DocumentationAdapter<Function>
    {
        public override void AddDocumentation(DocumentationScope documentationScope, Function node)
        {
            base.AddDocumentation(documentationScope, node);

            // Create declarations for the parameters and add it to the block's scope
            var bodyScope = node.InnerScope as DocumentationScope;
            if (bodyScope != null)
            {
                var parameters = node.GetParameterIdentifiers().Select(identifier => DeclarationFactory.CreateDeclaration<Parameter>(identifier, true));
                bodyScope.AddRange(parameters.Cast<Declaration>());
            }
        }
    }
}